package com.ayou.eggguard.farm.service.impl;

import com.ayou.common.utils.PageBean;
import com.ayou.eggguard.farm.mapper.WarningConfigMapper;
import com.ayou.eggguard.farm.pojo.WarningConfig;
import com.ayou.eggguard.farm.service.WarningConfigService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class WarningConfigServiceImpl implements WarningConfigService {

    @Autowired
    private WarningConfigMapper warningConfigMapper;

    @Override
    public PageBean<WarningConfig> getConfigList(Integer pageNum, Integer pageSize, String warningType) {
        PageBean<WarningConfig> pb=new PageBean<>();
        PageHelper.startPage(pageNum,pageSize);
        List<WarningConfig> list=warningConfigMapper.getConfigList(warningType);
        Page<WarningConfig> p= (Page<WarningConfig>) list;
        pb.setItems(p.getResult());
        pb.setTotal(p.getTotal());
        return pb;
    }

    @Override
    public WarningConfig getConfigByName(String warningType) {
        return warningConfigMapper.getConfigByName(warningType);
    }

    @Override
    public void add(WarningConfig warningConfig) {
        warningConfigMapper.add(warningConfig);
    }
}
